package psd.model.Prolog.Converters;

import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.BreakStatement;
import org.eclipse.jdt.core.dom.SimpleName;

import psd.model.IConverter;
import psd.model.Prolog.FactGenerationToolbox;
import psd.model.Prolog.PrologConverter;


public class PrologBreakStatementConverter extends PrologConverter implements
IConverter<BreakStatement>{

	public PrologBreakStatementConverter(FactGenerationToolbox toolbox) {
		super(toolbox);
	}

	@Override
	public boolean convert(BreakStatement node) {
		  SimpleName n = node.getLabel();
	        String label;
	        String target;
	        if(n != null)
	        {
	            label = PrologCommon.quote(n);
	            target = idResolver.getID((ASTNode)labels.get(n.getIdentifier()));
	        } else
	        {
	            label = "'null'";
	            target = idResolver.getID(getEnclosingIterator(node));
	        }
	        String args[] = {
	            label, target
	        };
	        createBodyFact(node, "breakT", args);
	        return true;
	}

}
